<?php
/**
 * IndexController
 *
 * @author
 * @version
 */

class Admin_IndexController extends AdminBaseController
{
	public function init()
	{
		parent::init();
	}
	/**
	 * The default action - show the home page
	 */
	public function indexAction ()
	{
		
	}
	
	public function loginAction ()
	{
		if ($this->_request->isPost())
		{
			$login = $this->_request->getParam('login');
			
			$dbAdapter = Zend_Registry::get('dbAdapter');
			$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
			$authAdapter->setTableName('admin_users');
			$authAdapter->setIdentityColumn('username');
			$authAdapter->setCredentialColumn('password');
			
			$authAdapter->setIdentity($login['username']);
			$authAdapter->setCredential(md5($login['password']));
			
			$auth = Zend_Auth::getInstance();
			$result = $auth->authenticate($authAdapter);
			
			if ($result->isValid())
			{
				$data = $authAdapter->getResultRowObject(null, 'password');
				
				$auth->getStorage()->write($data);
				$this->_redirector->gotoSimple('index', 'dashboard', 'admin');
			}else {
				$this->view->message = $this->_languages->_('Access Denied.');
				$this->view->username = $login['username'];
			}
		}
	}
	
	public function logoutAction()
	{
		Zend_Auth::getInstance()->clearIdentity();
		$this->_redirector->gotoSimple('login', 'index', 'admin');
	}
}
?>